package com.htc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.htc.dao.ClassesMapper;
import com.htc.dao.ProductMapper;
import com.htc.error.ClassesExistsDrugException;
import com.htc.model.Classes;
import com.htc.model.PageResult;
import com.htc.model.request.ClassesRequest;

@Service
public class ClassesService {
    
	@Autowired
	private ClassesMapper classesMapper;
	@Autowired
	private ProductMapper productMapper;
	
	public List<Classes> queryList(ClassesRequest request) {
		List<Classes> list =  classesMapper.queryList(request.convertWhereStr());
		return list;
	}
	
	public void add(Classes room) {
		classesMapper.insert(room);
	}
	
	public void update(Classes room) {
		classesMapper.update(room);
	}
	
	public void del(int id) {
		checkDelClasses(id);
		classesMapper.del(id);
	}

	public List<Classes> findAll() {
		return classesMapper.queryList("");
	}
	
	public void checkDelClasses(int id) {
		Long count = productMapper.queryByClasses(id);
		if(count!=null&&count>0) {
			throw new ClassesExistsDrugException();
		}
	}
	
	

}
